package spring.provider;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试使用接口，服务提供者
 */
@RestController
public class Controller {
    @RequestMapping("/car/{name}")
    @HystrixCommand(fallbackMethod = "hystrixGar")
    public String car(@PathVariable String name){
        if(name.length() < 3){
            throw new RuntimeException("hystrixGar测试");
        }
        return "02：car的name：" + name;
    }

    //备选方法
    public String hystrixGar(@PathVariable String name){
        return "hystrix： 针对car的接口请求失败";
    }


    @RequestMapping("/plane/{name}")
    public String plane(@PathVariable String name){
        return "02：plane的name：" + name;
    }
}
